set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO






--银行借款 1=财,2=转,3=银,1=银行借款，2=银行还款
CREATE procedure [dbo].[sp_jiuqi_jkinput_list] @xxtype int,@xxid int,@isignseq int output,@csign varchar(100) output

AS

declare @jkid int,@bankid int,@compid int,@je numeric(18,2),@note varchar(255)
if @xxtype=1
  select @jkid=@xxid
else
  select @jkid=xxid from t_cw_bank_dtl where pkid=@xxid

select @bankid=bankid,@compid=compid,@je=je from t_cw_jk where jkid=@jkid

if @xxtype=2
  select @je=je from t_cw_bank_dtl where pkid=@xxid

select @isignseq=dbo.gf_cw_sys_isignseq(dbo.gf_sys_cwcompid_by_compid(compid),u8type) from t_cw_bank where bankid=@bankid
select @csign=dbo.gf_cw_sys_csign(dbo.gf_sys_cwcompid_by_compid(@compid),@isignseq)

declare @ccode1 varchar(100),@ccname1 varchar(100),@je1 numeric(18,2),@isproc1 int
declare @ccode2 varchar(100),@ccname2 varchar(100),@je2 numeric(18,2),@isproc2 int


if @xxtype=1
  begin
    select @note='借'+(select name from t_cw_bank where bankid=@bankid)+'银行短期借款'

    select @ccode1=(select jiuqi_saving_code from t_cw_bank where bankid=@bankid)--select u8code from t_cw_bank where bankid=@bankid)
    select @ccname1='银行存款/'+(select name from t_cw_bank where bankid=@bankid)
    select @je1=isnull(@je,0)
    select @isproc1=1

    select @ccode2=(select jiuqi_loan_code from t_cw_bank where bankid=@bankid)--select u8code2 from t_cw_bank where bankid=@bankid)
    select @ccname2='短期借款/'+(select name from t_cw_bank where bankid=@bankid)
    select @je2=isnull(@je,0)
    select @isproc2=0
  end

if @xxtype=2
  begin
    select @note='还'+(select name from t_cw_bank where bankid=@bankid)+'银行短期借款'

    select @ccode1=(select jiuqi_loan_code from t_cw_bank where bankid=@bankid)--select u8code2 from t_cw_bank where bankid=@bankid)
    select @ccname1='短期借款/'+(select name from t_cw_bank where bankid=@bankid)
    select @je1=isnull(@je,0)
    select @isproc1=0

    select @ccode2=(select jiuqi_saving_code from t_cw_bank where bankid=@bankid)--select u8code from t_cw_bank where bankid=@bankid)
    select @ccname2='银行存款/'+(select name from t_cw_bank where bankid=@bankid)
    select @je2=isnull(@je,0)
    select @isproc2=1
  end

select
  note=@note,
  ccode=@ccode1,
  ccname=@ccname1,
  md=@je1,
  mc=0.00,
  ismd=1,
  ismc=0,
  ccus_id=null,
  csup_id=null,
  isdept=0,
  isproc=@isproc1

union all

select
  note=@note,
  ccode=@ccode2,
  ccname=@ccname2,
  md=0.00,
  mc=@je2,
  ismd=1,
  ismc=0,
  ccus_id=null,
  csup_id=null,
  isdept=0,
  isproc=@isproc2














